
$(function() {

	$("#province_s").autocomplete({
		minLength: 0,
		source: function( request, response ) {
			var matcher = new RegExp( $.ui.autocomplete.escapeRegex( request.term ), "i" );
			
			response( $.map( provinces, function( item ) {
				if ( item && ( !request.term || matcher.test(item.zjm) ) )
					return {
					label: item.name + " [" + item.zjm + "]",
					value: item.name
				};
			}) );
		}
	});	

	$("#city_s").autocomplete({
		source: function( request, response ) {
			$.ajax({
				url: 'info.php?do=Zone.ajax_zjm',
				dataType: "json",
				data: {
					province: $("#province_s").val(),
					style: "full",
					maxRows: 12,
					q: request.term
				},
				success: function( data ) {
					response( $.map( data, function( item ) {
						return {
							label: item.city + " [" + item.zjm + ", " + item.province.trim() + ", " + item.zone.trim() + "]",
							value: item.city
						}
					}));
				}
			});
		},
		
		minLength: 1
	});
	
	$("#district_s").autocomplete({
		source: function( request, response ) {
			$.ajax({
				url: 'info.php?do=District.ajax_zjm',
				dataType: "json",
				data: {
					province: $("#province_s").val(),
					city: $("#city_s").val(),
					maxRows: 12,
					q: request.term
				},
				success: function( data ) {
					response( $.map( data, function( item ) {
						return {
							label: item.district + " [" + item.zjm + ", " + item.province.trim() + ", " + item.city.trim() + "]",
							value: item.district
						}
					}));
				}
			});
		},
		
		minLength: 1
	});
});

function test() {
	var s = $('#province').val();
	alert(s);
}
